<template>
  <el-autocomplete
    v-model="inputValue"
    placeholder="编辑单位"
    :fetch-suggestions="querySearch"
    value-key="name"
    :trigger-on-focus="false"
  ></el-autocomplete>
</template>

<script>
export default {
  name: 'component-edit-company',
  props: {
    company: String,
    editing: Boolean,
  },
  data() {
    return {
      inputValue: '',
    };
  },
  methods: {
    querySearch(query, callback) {
      if (query === '') return;
      this.$api.search.fn({
        type: 'School',
        title: query,
      }).then(res => callback(res.data))
        .catch(() => {});
    },
    resetValue() {
      this.inputValue = this.company;
    },
  },
  watch: {
    editing(val) {
      if (val) this.resetValue();
    },
    inputValue(val) {
      this.$emit('input', val);
    },
  },
};
</script>

<style></style>
